package com.scut.edu.wanyou.home.talk;

import org.jivesoftware.smack.AccountManager;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;

import android.R.bool;

public class LoginAndReg {
	public  Connection connection ;
	public LoginAndReg()
	{
		XmppTool.openConnection();
		connection = XmppTool.getConnection();
	}
	public  boolean Login(String id,String password)
	{
		
		try {
			connection.login(id, password);
			Presence presence = new Presence(Presence.Type.available);
			connection.sendPacket(presence);
			return true;
		} catch (XMPPException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	public boolean register(String id,String password)
	{
		AccountManager account = connection.getAccountManager();
		try {
			account.createAccount(id, password);
			return true;
		} catch (XMPPException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	public boolean logout()
	{
		Presence presence = new Presence(Presence.Type.unavailable);
		connection.sendPacket(presence);
		connection.disconnect();
		connection = null;
		return true;
	}
}
